package com.yay.rental.provider;


import com.yay.rental.provider.RentalDatabase.Tables;
import android.net.Uri;
import android.provider.BaseColumns;

/**
 * Get Started!
 * @author team@getstarted.com.ua
 *
 * Contract class for interacting with {@link RentalProvider}. Unless
 * otherwise noted, all time-based fields are milliseconds since epoch and can
 * be compared against {@link System#currentTimeMillis()}.
 * <p>
 * The backing {@link ContentProvider} assumes that {@link Uri} are generated
 * using stronger {@link String} identifiers, instead of {@code int}
 * {@link BaseColumns#_ID} values, which are prone to shuffle during sync.
 */
public class RentalContract {

    public interface CategoriesColumns extends BaseColumns {
        /** Unique string identifying parent category. */
    	String IDP = "idp";
        /** Name describing this category. */
        String NAME = "name";
    }
    
    public interface RentalColumns extends BaseColumns {
    	/** Category id. */
        String IDP = "idp";
        /** Name describing this rental. */
        String NAME = "name";
        /** Rental price. */
        String PRICE = "price";
        /** Rental accommodations. */
        String ACCOMMODATIONS = "accommodations";
        /** Rental description. */
        String DESCRIPTION = "description";
    }
    
    public static final String CONTENT_AUTHORITY = "com.yay.rental";
    private static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
    private static final String PATH_CATEGORY = "category";
    private static final String PATH_RENTAL = "rental";
    private static final String PATH_MAP = "map";
    
    /**
     * Category are overall categories for {@link Rental}
     */
    public static class Category implements CategoriesColumns, BaseColumns {
        public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_CATEGORY).build();
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.m5.category";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = CategoriesColumns._ID + " ASC";

        /** Build {@link Uri} for requested {@link #ID}. */
        public static Uri buildCategoryUri(String categoryId) {
            return CONTENT_URI.buildUpon().appendPath(categoryId).build();
        }

        /**
         * Build {@link Uri} that references any {@link Recipe} associated
         * with the requested {@link #ID}.
         */
        public static Uri buildRentalUri(String categoryId) {
            return CONTENT_URI.buildUpon().appendPath(categoryId).appendPath(PATH_RENTAL).build();
        }

        /** Read {@link #ID} from {@link Category} {@link Uri}. */
        public static String getCategoryId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

    }

    /**
     * Each recipe is a block that has instructions and ingredients
     */
    public static class Rental implements RentalColumns, BaseColumns {
        public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_RENTAL).build();
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.m5.rental";
        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.m5.rental";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = Tables.RENTALS + "." + RentalColumns.NAME + " COLLATE NOCASE ASC";
        
        /** Build {@link Uri} for requested {@link #RENTAL_ID}. */
        public static Uri buildRentalUri(int rentalId) {
            return CONTENT_URI.buildUpon().appendPath(""+rentalId).build();
        }

        /** Read {@link #_ID} from {@link Rental} {@link Uri}. */
        public static String getRentalId(Uri uri) {
            return uri.getPathSegments().get(1);
        }
    }
    
    public static class RentalMap {
        public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_MAP).build();
        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.m5.map";
    }
    
    private RentalContract() {
    }
}
